//
//  NLoginChooseThemeViewController.m
//  News
//
//  Created by zhangtao on 2018/11/6.
//  Copyright © 2018年 zt.td. All rights reserved.
//

#import "NLoginChooseThemeViewController.h"

#import "NThemeCollectionViewCell.h"
#import "AppDelegate.h"


@interface NLoginChooseThemeViewController ()<UICollectionViewDelegate,UICollectionViewDataSource,UICollectionViewDelegateFlowLayout>
@property(nonatomic,strong)UICollectionView *collection;


@end

@implementation NLoginChooseThemeViewController
static NSString * const reuseIdentifier = @"Cell";

- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = [UIColor whiteColor];
    [self createUI];

}

-(void)backClick{
    
}

-(void)waitClick{
        AppDelegate *app = (AppDelegate *)[UIApplication sharedApplication].delegate;
        [app setMainRootViewController];
    
}

-(void)createUI{
    
    UIButton *back = [[UIButton alloc]initWithFrame:CGRectMake(15, navHeight-64+20, 25, 25)];
    [back setImage:[UIImage imageNamed:@"48-48jt"] forState:UIControlStateNormal];
    [back addTarget:self action:@selector(backClick) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:back];
    
    UILabel *theme = [[UILabel alloc]initWithFrame:CGRectMake(0, navHeight+15, ACEWidth, 25)];
    theme.textAlignment = NSTextAlignmentCenter;
    theme.text = @"选择您感兴趣的主题";
    theme.font = [UIFont boldSystemFontOfSize:23];
    [self.view addSubview:theme];
    
    UIButton *waitBtn = [[UIButton alloc]initWithFrame:CGRectMake(20, CGRectGetMaxY(theme.frame)+10,ACEWidth-40,20)];
    waitBtn.titleLabel.font = [UIFont systemFontOfSize:15];
    [waitBtn setTitle:@"就选这几个，先看看>>>" forState:UIControlStateNormal];
    [waitBtn setTitleColor:MAIN_COLOR forState:UIControlStateNormal];
    [waitBtn addTarget:self action:@selector(waitClick) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:waitBtn];
    
    UIButton *changeBtn = [[UIButton alloc]initWithFrame:CGRectMake(self.view.center.x-30, CGRectGetMaxY(waitBtn.frame)+15, 80, 26)];
    changeBtn.titleLabel.font = [UIFont boldSystemFontOfSize:14];
    changeBtn.layer.cornerRadius = 13;
    changeBtn.layer.masksToBounds = YES;
    changeBtn.backgroundColor = MAIN_COLOR;
    [changeBtn setTitle:@"换一批" forState:UIControlStateNormal];
    [self.view addSubview:changeBtn];
    
    
    UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc]init];
    self.collection = [[UICollectionView alloc]initWithFrame:CGRectMake(0, CGRectGetMaxY(changeBtn.frame)+10, ACEWidth,ACEHeight-CGRectGetMaxY(changeBtn.frame)+10-100 /*((ACEWidth-40)/3+80)*2*/) collectionViewLayout:layout];
    self.collection.backgroundColor = [UIColor whiteColor];
    self.collection.delegate = self;
    self.collection.dataSource = self;
    [self.view addSubview:self.collection];
    
    [self.collection registerNib:[UINib nibWithNibName:@"NThemeCollectionViewCell" bundle:nil] forCellWithReuseIdentifier:reuseIdentifier];
    
    
    UIButton *waitBtn1 = [[UIButton alloc]initWithFrame:CGRectMake(20, ACEHeight-70,ACEWidth-40,20)];
    waitBtn1.titleLabel.font = [UIFont systemFontOfSize:15];
    [waitBtn1 setTitle:@"就选这几个，先看看>>>" forState:UIControlStateNormal];
    [waitBtn1 setTitleColor:MAIN_COLOR forState:UIControlStateNormal];
    [waitBtn1 addTarget:self action:@selector(waitClick) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:waitBtn1];
    
}


#pragma mark <UICollectionViewDataSource>

- (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView {
    return 1;
}


- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
    return 10;
}

- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
    NThemeCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:reuseIdentifier forIndexPath:indexPath];
    
    return cell;
}

-(CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath{
    return CGSizeMake((ACEWidth-40)/3, (ACEWidth-40)/3+80);
}

-(UIEdgeInsets)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout insetForSectionAtIndex:(NSInteger)section{
    return UIEdgeInsetsMake(10, 10, 10, 10);
    //    return UIEdgeInsetsZero;
}

-(void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath{
//    NThemeDetailViewController *detail = [[NThemeDetailViewController alloc]init];
//    detail.hidesBottomBarWhenPushed = YES;
//    [self.navigationController pushViewController:detail animated:YES];
}

//设置水平间距 (同一行的cell的左右间距）
-(CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout minimumInteritemSpacingForSectionAtIndex:(NSInteger)section {
    return 10;
}
//垂直间距 (同一列cell上下间距)
- (CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout minimumLineSpacingForSectionAtIndex:(NSInteger)section {
    return 10;
}

@end
